package com.example.demo.utils;

import org.apache.commons.codec.digest.DigestUtils;

/**
 *加密工具类
* @desc: 
* @author: weili23
* @createTime: 2022年3月28日 下午5:14:48
* @history:
* @version: v1.0
 */
public class MD5Util {

	
	public static String md5(String src) {
		return DigestUtils.md5Hex(src);
	}
	
	
	private static final String salt ="sdf32343dg223f"; //随便定义盐
	
	//输入的密码第一次加密
	public static String inputPassToFromPass(String inputPass) {
		String str = salt.charAt(0)+salt.charAt(2)+salt.charAt(4)+inputPass+salt.charAt(1)+salt.charAt(3);
		return md5(str);
	}
	
	//加密后的密码  在加密
	public static String fromPassToDBPass(String fromPass,String salt) {
		String str = salt.charAt(0)+salt.charAt(2)+salt.charAt(4)+fromPass+salt.charAt(1)+salt.charAt(3);
		return md5(str);
	}
	
	
	public static String inputPassToDBPass(String inputPass,String salt) {
		String s = inputPassToFromPass(inputPass);
		String result = fromPassToDBPass(s,salt);
		return result;
	}
	
	
	public static void main(String[] args) {
		System.out.println(inputPassToFromPass("123456"));
		//c214ddbec08fc184fea1d48bea6ebe68
		System.out.println(fromPassToDBPass("c214ddbec08fc184fea1d48bea6ebe68","123456"));
		System.out.println(inputPassToDBPass("123456","123456"));
	}
	
}
